package com.monkeysonnet.b2dFluent;

import com.badlogic.gdx.physics.box2d.Joint;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.physics.box2d.joints.GearJoint;
import com.badlogic.gdx.physics.box2d.joints.GearJointDef;

public class GearJointFactory extends JointFactory<GearJointFactory>
{
	private static final GearJointDef _initialDef = new GearJointDef();
	
	private GearJointDef _def;
	
	public GearJointFactory()
	{
		this(false);
	}
	
	GearJointFactory(boolean managed)
	{
		super(managed);
		_def = new GearJointDef();
		setDef(_def);
	}
	
	public GearJointFactory joint1(Joint j)
	{
		_def.joint1 = j;
		return this;
	}
	
	public GearJointFactory joint2(Joint j)
	{
		_def.joint2 = j;
		return this;
	}
	
	public GearJointFactory ratio(float r)
	{
		_def.ratio = r;
		return this;
	}
	
	public GearJoint create(World w)
	{
		return (GearJoint)w.createJoint(_def);
	}
	
	void clear()
	{
		super.clear(_initialDef);
		_def.joint1 = _initialDef.joint1;
		_def.joint2 = _initialDef.joint2;
		_def.ratio = _initialDef.ratio;
	}

	@Override
	public void free()
	{
		B2d.free(this);
	}
}
